package pattern.factory;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.WeakHashMap;

/**
 * 工厂模式（Factory）
 */
public class FactoryPatternDemo {

    public static void main(String[] args) {
        ShapeFactory shapeFactory = new ShapeFactory();

        // 获取 Circle 的对象，并调用它的 draw 方法
        Shape shape1 = shapeFactory.getShape("CIRCLE");
        // 调用 circle 的 brew 方法
        shape1.draw();
        Map<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("text", "Inside Circle::getMap() method.");
        System.out.println(shape1.getMap(hashMap).get("text"));

        //获取 Rectangle 的对象，并调用它的 draw 方法
        Shape shape2 = shapeFactory.getShape("RECTANGLE");
        //调用 Rectangle 的 draw 方法
        shape2.draw();
        Map<String, Object> linkedHashMap = new LinkedHashMap<>();
        linkedHashMap.put("text", "Inside Circle::getMap() method.");
        System.out.println(shape1.getMap(linkedHashMap).get("text"));

        Shape shape3 = shapeFactory.getShape("SQUARE");
        shape3.draw();
        Map<String, Object> weakHashMap = new WeakHashMap<>();
        weakHashMap.put("text", "Inside Circle::getMap() method.");
        System.out.println(shape3.getMap(weakHashMap).get("text"));
    }
}
